/**
 * 
 */
package com.alibaba.hello.validate;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.ObjectError;
import org.springframework.validation.Validator;
import org.springmodules.validation.valang.ValangValidator;

import com.alibaba.hello.dataobject.Address;
import com.alibaba.hello.dataobject.Student;

/**
 * @author sesame.yangj
 * 
 */
public class UserValidator extends ValangValidator {
	private Validator addressValidator;

	public void validate(Object target, Errors errors) {
		super.validate(target, errors);
		Address address = ((Student) target).getAddress();
		// address 为 null 时，不进行进一步的验证。
		if (null != address) {
			// 注意与 popNestedPath 成对使用
			errors.pushNestedPath("address");
			// 验证 address
			addressValidator.validate(address, errors);
			errors.popNestedPath();
		}
	}

	public Validator getAddressValidator() {
		return addressValidator;
	}

	public void setAddressValidator(Validator addressValidator) {
		this.addressValidator = addressValidator;
	}
}
